package cn.edu.fzu.homemaking.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.edu.fzu.homemaking.domain.entity.SysArea;
import cn.edu.fzu.homemaking.domain.entity.SysCity;
import cn.edu.fzu.homemaking.domain.entity.SysProvince;
import cn.edu.fzu.homemaking.service.SysAreaService;
import cn.edu.fzu.homemaking.service.SysCityService;
import cn.edu.fzu.homemaking.service.SysProvinceService;
import cn.edu.fzu.homemaking.web.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * @author yifan
 * @date 2023/4/8
 */
@Api(tags = "省市地区列表")
@RestController
@RequestMapping("/api/sys")
public class SysAreaController {

    @Resource
    private SysProvinceService sysProvinceService;

    @Resource
    private SysCityService     sysCityService;

    @Resource
    private SysAreaService     sysAreaService;

    @ApiOperation(value = "省份列表")
    @GetMapping("/listProvince")
    public Result listProvince() {
        List<SysProvince> provinces = sysProvinceService.list();
        return new Result(provinces);
    }


    @ApiOperation(value = "城市列表")
    @GetMapping("/listCity")
    public Result listCity(Long provinceId) {
        List<SysCity> cities = sysCityService.list(provinceId);
        return new Result(cities);
    }


    @ApiOperation(value = "地区列表")
    @GetMapping("/listArea")
    public Result listArea(Long cityId) {
        List<SysArea> areas = sysAreaService.list(cityId);
        return new Result(areas);
    }

    @ApiOperation(value = "获取指定地区")
    @GetMapping("/getAreaById")
    public Result getAreaById(Long areaId) {
        SysArea area = sysAreaService.getById(areaId);
        return new Result(area);
    }
}
